<?php


namespace app\controller;

use app\common\controller\BaseController;
use app\common\service\content\CategoryService;
use app\common\service\content\ContentService;

use app\common\service\setting\CarouselService;
use app\api\service\IndexService;
use hg\apidoc\annotation as Apidoc;
use think\facade\View;

/**
 * @Apidoc\Title("首页")
 * @Apidoc\Group("index")
 * @Apidoc\Sort("100")
 */
class Index extends BaseController
{
    /**
     * @Apidoc\Title("首页")
     * @Apidoc\NotHeaders()
     * @Apidoc\NotQuerys()
     * @Apidoc\NotParams()
     */
    public function index()
    {

        $where[] = where_disable();
        $where[] = where_delete();


        $order = ['sort' => 'desc', 'carousel_id' => 'desc'];

        $banner =  CarouselService::list($where, 1, 100, $this->order($order));
        $bannerList = $banner['list'];
        $bannerType1 = [];
        $bannerType2 = [];
        foreach ($bannerList as $banner) {
            if ($banner['type'] == 1) {
                $bannerType1[] = $banner;
            } elseif ($banner['type'] == 2) {
                $bannerType2[] = $banner;
            }
        }

        View::assign('banner', $bannerType1);
        View::assign('sjbanner', $bannerType2);

        $cpmenu = CategoryService::getSubMenu(3);
        View::assign('cpmenu', $cpmenu);


        $ids = CategoryService::getSubMenuIds(6);
        $where[] = ['category_ids', 'in', $ids];
        $where[] = ['type', '=', 1];
        $newList =   ContentService::lis($where, 1, 12);

        View::assign('newList', $newList);
        return view('index');
    }
}
